/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UserInterface.Result;

import Business.Launcher.Admin.LaunchAdmin;
import Business.Record.Record;
import Business.RecordsOperation.RecordsOperation;
import java.awt.event.WindowEvent;
import java.util.Iterator;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author hooting
 */
public class ResultJFrame extends javax.swing.JFrame {

	/**
	 * Creates new form ResultJFrame
	 */
	public ResultJFrame() {
		initComponents();
		this.setLocationRelativeTo(null);
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {

                jLabel1 = new javax.swing.JLabel();
                cmbTitle = new javax.swing.JComboBox();
                lblLabel = new javax.swing.JLabel();
                jLabel2 = new javax.swing.JLabel();
                jScrollPane1 = new javax.swing.JScrollPane();
                txtDescription = new javax.swing.JTextArea();
                btnReturn = new javax.swing.JButton();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

                jLabel1.setText("Title");

                cmbTitle.addItemListener(new java.awt.event.ItemListener() {
                        public void itemStateChanged(java.awt.event.ItemEvent evt) {
                                cmbTitleItemStateChanged(evt);
                        }
                });

                jLabel2.setText("Description");

                txtDescription.setEditable(false);
                txtDescription.setColumns(20);
                txtDescription.setLineWrap(true);
                txtDescription.setRows(5);
                jScrollPane1.setViewportView(txtDescription);

                btnReturn.setText("Return");
                btnReturn.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                btnReturnActionPerformed(evt);
                        }
                });

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(jScrollPane1)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                        .addComponent(lblLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addGroup(layout.createSequentialGroup()
                                                                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                .addComponent(cmbTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addComponent(jLabel2))))
                                        .addGroup(layout.createSequentialGroup()
                                                .addGap(137, 137, 137)
                                                .addComponent(btnReturn)))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cmbTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnReturn)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                );

                pack();
        }// </editor-fold>//GEN-END:initComponents

        private void btnReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReturnActionPerformed
			this.dispose();
			LaunchAdmin.showAdminJFrame();
                // TODO add your handling code here:
        }//GEN-LAST:event_btnReturnActionPerformed

        private void cmbTitleItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbTitleItemStateChanged
			showDescription();
                // TODO add your handling code here:
        }//GEN-LAST:event_cmbTitleItemStateChanged
	
		public void setTitles(String[] titles){
			cmbTitle.setModel(new DefaultComboBoxModel(titles));
		}
		public void showDescription(){
			List<Record> list = new RecordsOperation().getAllRecords();
			if(list.size() == 0){
				return;
			}
			Iterator<Record> ite = list.iterator();
			Record r = null;
			String s = (String)cmbTitle.getSelectedItem();
			while(ite.hasNext()){
				r = ite.next();
				if(r.title.equals(s))
					break;
			}
			lblLabel.setText("Label:  " + r.participantType + "," + r.eventType
				+ "," + r.country + "," + r.provincy + "," + r.hospital);
			txtDescription.setText(r.description);
		}
		protected void processWindowEvent(WindowEvent e){
			if(e.getID() == WindowEvent.WINDOW_CLOSING){
			}else{
				super.processWindowEvent(e);
			}
		}
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JButton btnReturn;
        private javax.swing.JComboBox cmbTitle;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JLabel lblLabel;
        private javax.swing.JTextArea txtDescription;
        // End of variables declaration//GEN-END:variables
}
